<template>
  <view class="router-view bcl-active " style="padding:10px;">

    <view class="" style="background:#fff;">
      
      
           <view v-if="type == 5">

           </view>
           <view v-else>
            <uni-cell title="开始时间" :noPointer="true">
              <view slot="value">
                <picker
                  mode="date"
                  @change="changeStartTime"
                  fields="month"
                  style="width: 200upx; height: 100upx;"
                >
                  <view class="input text-right">
                    <text>{{ startTime || "请选择开始时间" }}</text>
                  </view>
                </picker>
              </view>
            </uni-cell>
            <uni-cell title="结束时间" :noPointer="true">
              <view slot="value">
                <picker
                  mode="date"
                  @change="changeEndTime"
                  fields="month"
                  style="width: 200upx; height: 100upx;"
                >
                  <view class="input text-right">
                    <text>{{ endTime || "请选择结束时间" }}</text>
                  </view>
                </picker>
              </view>
            </uni-cell>
           </view>
          <uni-cell :title="type==1 ? '项目名称': type == 2 ? '项目名称': type == 3 ? '学校名称':type==4 ? '机构名称':type==5 ? '语言':'项目名称'" :noPointer="true">
              <view slot="value" class="text-right">
                <input
                  type="text"
                  class="uni-input height"
                  :placeholder="type==1 ? '项目名称': type == 2 ? '项目名称': type == 3 ? '学校名称':type==4 ? '机构名称':type==5 ? '语言':'项目名称'"
                  v-model="name"
                />
              </view>
         </uni-cell>
          <uni-cell :title="type==1 ? '职位名称': type == 2 ? '职位名称': type == 3 ? '专业名称':type==4 ? '培训课程':type==5 ? '听说能力':'职位名称'" :noPointer="true">
              <view slot="value" class="text-right">
                <input
                  type="text"
                  class="uni-input height"
                  :placeholder="type==1 ? '职位名称': type == 2 ? '职位名称': type == 3 ? '专业名称':type==4 ? '培训课程':type==5 ? '听说能力':'职位名称'"
                  v-model="cons"
                />
              </view>
           </uni-cell>
           <view v-if="type == 4">

           </view>
           <view v-else>
              <uni-cell  :title="type==1 ? '项目描述': type == 2 ? '项目描述': type == 3 ? '学历':type==5 ? '读写能力':'项目描述'" :noPointer="true">
                  <view slot="value" class="text-right">
                    <input
                      type="text"
                      class="uni-input height"
                      placeholder="项目描述"
                      :placeholder="type==1 ? '项目描述': type == 2 ? '项目描述': type == 3 ? '学历':type==5 ? '读写能力':'项目描述'"
                      v-model="dec"
                    />
                  </view>
              </uni-cell>
           </view>
           
        <button
          class="uni-button uni-button-lg uni-button-full mt-30"
          @tap="saveInfo"
        >
          保存
        </button>
    </view>
   
  <!-- <u-cell-item  title="项目名称"  :arrow="false" right >
			
      <view slot="value" class="text-right">
        <u-input type="text"  placeholder="学校名称"/>
                <!-- <input
                  type="text"
                  class="uni-input height"
                  placeholder="学校名称"
                  v-model="experience.name"
                /> -->
              <!-- </view> -->
	</u-cell-item> 
  </view>
</template>

<script>
import {
  userIntro,
  delProject,
  delJob,
  addProject,
  addJob,
  editProject,
  editJob,
  addEduition,
  resumeTrainingsSave,
  resumeLanguagesSave
} from "@/apis/user";

import uniCell from "@/components/cell";
export default {

  components: {
    uniCell,
  },
  data() {
    return {
      startTime:'',
      endTime:'',
      name:'',
      cons:'',
      dec:'',
      experience: {
        startTime: "",
        endTime: "",
        name: "",
        jobs: "",
        achievements: "",
      },
      type:''
    };
  },

  onLoad(options) {
    // console.log("options",options)
    this.type =  options.type
    var type = options.type
    var titie;
    if(type == 1){
      titie = '添加工作经验'
    }
    if(type == 2){
      titie = '添加项目经验'
    }
    if(type == 3){
      titie = '添加个人教育'
    }
    if(type == 4){
      titie = '添加培训经历'
    }
    if(type == 5){
      titie = '添加语言能力'
    }
    if(type == 6){
      titie = '添加证书'
    }
    if(type == 7){
      titie = '添加加密锁'
    }
    uni.setNavigationBarTitle({
      title: titie
    })
    // this.getUserIntro();
  },

  methods: {

    async saveInfo(){
      var params = {
          startTime:this.startTime,
          endTime:this.endTime,
          start_year: this.startTime.substring(0, 4),
          start_month: this.startTime.substring(5, 7),
          end_year: this.endTime.substring(0, 4),
          end_month: this.endTime.substring(5, 7),
          name: this.name,
          jobs: this.cons,
          achievements: this.dec,
          company_name:this.name,
          project_name:this.name,
      };
      let requestFn = null;
      if(this.type == 1){
        requestFn = addJob
      }
      if(this.type == 2){
        requestFn = addProject
      }
      if(this.type == 3){
        var params = {
            startTime:this.startTime,
            endTime:this.endTime,
            start_year: this.startTime.substring(0, 4),
            start_month: this.startTime.substring(5, 7),
            end_year: this.endTime.substring(0, 4),
            end_month: this.endTime.substring(5, 7),
            name: this.name,
            jobs: this.cons,
            achievements: this.dec,
            company_name:this.name,
            project_name:this.name,
            school_name: this.name,
            speciality: this.cons,
            education:this.dec
        };
        requestFn = addEduition
      }
      if(this.type == 4){
        var params = {
            start_date:this.startTime,
            end_date:this.endTime,
            institution_name: this.name,
            training_course: this.cons,
            resume_type:'trainings',
            id:''
        };
        requestFn = resumeTrainingsSave
      }
      if(this.type == 5){
        var params = {
            start_date:this.startTime,
            end_date:this.endTime,
            language: this.name,
            listening_and_speaking: this.cons,
            literacy: this.dec,
            resume_type:'languages',
            id:''
        };
        requestFn = resumeLanguagesSave
      }
      let { code, data } = await requestFn(params);
      if (code === 200) {
        // await this.getUserIntro();
        
        this.$toast("操作成功");
        setTimeout(()=>{
         
        uni.navigateBack();
        },1000);
      }
    },
    
    // 日期更改回调
    changeStartTime(event) {
      this.startTime = event.target.value.substring(0, 7);
    },

    changeEndTime(event) {
      this.endTime = event.target.value.substring(0, 7);
    },
  

    
  },
};
</script>

<style lang="scss" scoped>
.router-view {
  .user-info {
    .uni-avatar {
      width: 100upx;
      height: 100upx;
      image {
        width: 100%;
        height: 100%;
        vertical-align: middle;
      }
    }
  }
  .work {
    .icon-plus {
      width: 40upx;
      height: 40upx;
      text-align: center;
      padding: 5upx;
    }

    .work-content {
      padding-top: 40upx;
      border-bottom: 1upx solid $color-border-deep;
      padding-bottom: 40upx;

      &:first-child {
        padding-top: 0;
      }

      &:last-child {
        padding-bottom: 0;
        border-bottom: 0;
      }

      .time-tag {
        padding: 10upx 20upx;
        border-radius: 100upx;
      }
    }
  }
  .uni-input {
    margin-bottom: 0;
    border: 0;
  }
}
</style>
